//
//  SAStatisticsTopUpHeaderView.m
//  saasRetail
//
//  Created by mac on 2023/2/5.
//

#import "SAStatisticsTopUpHeaderView.h"
#import "SAStatisticsTopUpModel.h"

@interface SAStatisticsTopUpHeaderView ()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *numLab;
@property (nonatomic, strong) UILabel *priceLab;
@property (nonatomic, strong) UILabel *givingLab;
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UIButton *detailBtn;
@property (nonatomic, strong) UIView *line2;

@end

@implementation SAStatisticsTopUpHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    return self;
}

-(void)setModel:(SAStatisticsTopUpModel *)model {
    _model = model;
    self.titleLab.text = model.empName;
    self.numLab.text = [NSString stringWithFormat:@"充值数:%0.lf",[model.count doubleValue]];
    NSString *amount = [NSString stringWithFormat:@"%0.2lf",[model.amount doubleValue]/100.f].getEffectivePointString;
    self.priceLab.text = [NSString stringWithFormat:@"充值金额:%@",amount];
    NSString *givenAmount = [NSString stringWithFormat:@"%0.2lf",[model.givenAmount doubleValue]/100.f].getEffectivePointString;
    self.givingLab.text = [NSString stringWithFormat:@"赠送金额:%@",givenAmount];
    
    self.detailBtn.hidden = [self.numLab.text isEqualToString:@"充值数:0"];
}

-(void)detailBtnClick {
    !self.selectBlock ?: self.selectBlock();
}

-(void)initUI {
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.line];
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.detailBtn];
    [self.contentView addSubview:self.numLab];
    [self.contentView addSubview:self.priceLab];
    [self.contentView addSubview:self.givingLab];
    [self.contentView addSubview:self.line2];
}

-(UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:SARectMake(30, 9, 90, 20)];
        _titleLab.textColor = kBlackColor;
        _titleLab.textAlignment = NSTextAlignmentLeft;
        _titleLab.font = kFont(15);
    }
    return _titleLab;
}

-(UIButton *)detailBtn {
    if (!_detailBtn) {
        _detailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _detailBtn.frame = SARectMake(kBaseScreenWidth - 80, 0, 80, 38);
        [_detailBtn setTitle:@"详细" forState:UIControlStateNormal];
        _detailBtn.titleLabel.font = kFont(15);
        [_detailBtn setTitleColor:kBuleColor forState:UIControlStateNormal];
        [_detailBtn addTarget:self action:@selector(detailBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _detailBtn;
}

-(UILabel *)numLab {
    if (!_numLab) {
        _numLab = [[UILabel alloc] initWithFrame:SARectMake(30, 33, 98, 20)];
        _numLab.textColor = kBlackColor;
        _numLab.font = kFont(15);
        _numLab.textAlignment = NSTextAlignmentLeft;
        _numLab.adjustsFontSizeToFitWidth = YES;
        _numLab.minimumScaleFactor = 0.8;
    }
    return _numLab;
}

-(UILabel *)priceLab {
    if (!_priceLab) {
        _priceLab = [[UILabel alloc] initWithFrame:CGRectMake(kScaleNum(130), kScaleNum(33), kScaleNum(120), kScaleNum(20))];
        _priceLab.textColor = kBlackColor;
        _priceLab.font = kFont(15);
        _priceLab.textAlignment = NSTextAlignmentLeft;
        _priceLab.adjustsFontSizeToFitWidth = YES;
        _priceLab.minimumScaleFactor = 0.8;
    }
    return _priceLab;
}

-(UILabel *)givingLab {
    if (!_givingLab) {
        _givingLab = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - kScaleNum(123), kScaleNum(33), kScaleNum(120), kScaleNum(20))];
        _givingLab.textColor = kBlackColor;
        _givingLab.font = kFont(15);
        _givingLab.textAlignment = NSTextAlignmentLeft;
        _givingLab.adjustsFontSizeToFitWidth = YES;
        _givingLab.minimumScaleFactor = 0.8;
    }
    return _givingLab;
}

-(UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScaleNum(1))];
        _line.backgroundColor = kLineColor;
    }
    return _line;
}

-(UIView *)line2 {
    if (!_line2) {
        _line2 = [[UIView alloc] initWithFrame:CGRectMake(0, kScaleNum(61), kScreenWidth, kScaleNum(1))];
        _line2.backgroundColor = kLineColor;
    }
    return _line2;
}

@end
